import http from '@/apis/http'
import { aiLearn, aiLearnPad, dreamQuestionBank } from '@/apis'
import { TARGET_BOOST_PATHS } from './path'

// school_id 转字符串类型
const transformSchoolIdToString = params => {
  let { school_id } = params
  if (!school_id) return params
  params.school_id = school_id?.toString()
  return params
}

// 错题靶向接口
export const getQuestionType = params => {
  return http.get(
    dreamQuestionBank +
      TARGET_BOOST_PATHS.questionType +
      `?subject_id=${params.subject_id}&stage_id=${params.stage_id}`
  )
}
export const postKeyPointTree = params => {
  return http.post(aiLearnPad + TARGET_BOOST_PATHS.keyPointTreePath, params)
}

// 个性化靶向接口   接口文档：https://showdoc.readboy.com/web/#/135/3161
export const getPersonalizedData = params => {
  console.log(params)
  return http.get(
    aiLearn +
      TARGET_BOOST_PATHS.personalizedDataPath +
      `?start_time=${params.start_time}&end_time=${params.end_time}&subject_id=${params.subject_id}&school_id=${params.school_id}&class_id=${params.class_id}&task_from=${params.task_from}`
  )
}

export const getPersonalizedStudentDetails = params => {
  return http.get(
    aiLearn +
      TARGET_BOOST_PATHS.personalizedStudentDetailsPath +
      `?student_id=${params.student_id}&start_time=${params.start_time}&end_time=${params.end_time}&class_id=${params.class_id}`
  )
}
export const getPersonalizedKnowledgeGraph = params => {
  return http.get(
    aiLearn +
      TARGET_BOOST_PATHS.personalizedKnowledgeGraphPath +
      `?student_id=${params.student_id}&start_time=${params.start_time}&end_time=${params.end_time}`
  )
}

export const getStudentExamDetails = params => {
  return http.get(
    aiLearn +
      TARGET_BOOST_PATHS.studentExamDetailsPath +
      `?student_id=${params.student_id}&start_time=${params.start_time}&end_time=${params.end_time}&class_id=${params.class_id}`
  )
}

export const getStudentAccuracyByDate = params => {
  return http.get(
    aiLearn +
      TARGET_BOOST_PATHS.studentAccuracyByDatePath +
      `?student_id=${params.student_id}&start_time=${params.start_time}&end_time=${params.end_time}&task_from=${params.task_from}`
  )
}

export const getStudentTaskStatistics = params => {
  return http.get(
    aiLearn +
      TARGET_BOOST_PATHS.studentTaskStatisticsPth +
      `?student_id=${params.student_id}&start_time=${params.start_time}&end_time=${params.end_time}&subject_id=${params.subject_id}`
  )
}

//知识点靶向接口
export const getKnowledgeTree = params => {
  return http.post(
    aiLearn + TARGET_BOOST_PATHS.knowledgePointPath,
    transformSchoolIdToString(params)
  )
}
export const getKnowledgeRecord = params => {
  return http.post(
    aiLearn + TARGET_BOOST_PATHS.knowledgeRecordPath,
    transformSchoolIdToString(params)
  )
}
export const getKnowledgeStudent = params => {
  return http.post(
    aiLearn + TARGET_BOOST_PATHS.knowledgeStudentPath,
    transformSchoolIdToString(params)
  )
}

// 获取举一反三题目
export function getJyfsQustions(params) {
  return http.post(dreamQuestionBank + TARGET_BOOST_PATHS.JyfsQustions, params)
}

// 获取学科网相似题
export function getXkwSimilarQuestions(questionID, params) {
  return http.post(
    dreamQuestionBank +
      `/v1/question/${questionID}/new_similar_questions/recommend`,
    params
  )
}

// 获取学生掌握度排行
export function getMasteryRank(params) {
  return http.post(
    `${aiLearn}${TARGET_BOOST_PATHS.masteryRank}`,
    transformSchoolIdToString(params)
  )
}
